package com.shine.app.ui;

import java.util.List;

import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shine.app.BaseActivity;
import com.shine.app.R;

public class ViewpagerActivity extends BaseActivity {

	protected ViewPager viewPager;
	protected ImageView imageView;
	protected TextView textView1;
	protected TextView textView2;
	protected TextView textView3;
	protected List<View> pagerList;
	protected int offset = 0;
	protected int currIndex = 0;
	protected int bitMapWidth;
	protected LinearLayout viewpagerLayout;
	protected View pageOne;
	protected View pageTwo;
	protected View pageThree;

	protected void InitViewPagerView() {
		viewpagerLayout = (LinearLayout) findViewById(R.id.linearLayout);
		viewPager = (ViewPager) findViewById(R.id.viewPager);
		imageView = (ImageView) findViewById(R.id.cursor);
		textView1 = (TextView) findViewById(R.id.text1);
		textView2 = (TextView) findViewById(R.id.text2);
		textView3 = (TextView) findViewById(R.id.text3);
		textView1.setTag(true);
		textView2.setTag(true);
		textView3.setTag(true);
	}

	protected void InitPagerImageView() {
		bitMapWidth = BitmapFactory.decodeResource(getResources(),
				R.drawable.line_switch).getWidth();
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		int screenW = dm.widthPixels;
		offset = (screenW / 3 - bitMapWidth) / 2;
		Matrix matrix = new Matrix();
		matrix.postTranslate(offset, 0);
		imageView.setImageMatrix(matrix);
	}

	public class PagerOnPageChangeListener implements OnPageChangeListener {
		int one = offset * 2 + bitMapWidth;
		int two = one * 2;

		public void onPageScrollStateChanged(int arg0) {
		}

		public void onPageScrolled(int arg0, float arg1, int arg2) {
		}

		public void onPageSelected(int postion) {
			Animation animation = new TranslateAnimation(one * currIndex, one
					* postion, 0, 0);
			currIndex = postion;
			animation.setFillAfter(true);
			animation.setDuration(300);
			imageView.startAnimation(animation);
		}
	}
}